package com.panshi.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.panshi.service.HomeService;
import com.panshi.vo.ArticleOkVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("home")
public class HomeController {
    @Autowired
    HomeService homeService;

    //查询主页页数
    @CrossOrigin(origins = "*", maxAge = 3600)
    @GetMapping("/page")
    @ResponseBody
    public int countHomePage() throws JsonProcessingException {
        return homeService.countHomePage();
    }

    //主页 图文热搜
    @CrossOrigin(origins = "*", maxAge = 3600)
    @GetMapping("/hot/bot")
    @ResponseBody
    public List<ArticleOkVO> hotBot() throws JsonProcessingException {
        return homeService.hotBot();
    }

    //主页 最新创作
    @CrossOrigin(origins = "*", maxAge = 3600)
    @GetMapping("/new")
    @ResponseBody
    public List<ArticleOkVO> listHomeNewArticleOkVOs() throws JsonProcessingException {
        return homeService.listHomeNewArticleOkVOs();
    }

    //主页 3条资讯
    @CrossOrigin(origins = "*", maxAge = 3600)
    @GetMapping("/load/{type}/{page}")
    @ResponseBody
    public List<ArticleOkVO> listHomeArticleOkVOs(@PathVariable(value = "type") Integer type, @PathVariable(value = "page") Integer page) throws JsonProcessingException {
        return homeService.listHomeArticleOkVOs(type, page);
    }
}
